package hot100.logos71To80;

import java.util.Stack;

/**
 * @author logos
 * date 2025/7/17 12:35
 * @version v1.0
 * @Package hot100.logos71To80
 */
public class logos72 {

    /**
     * 72. 每日温度
     * https://leetcode.cn/problems/daily-temperatures/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int[] dailyTemperatures(int[] temperatures) {
            Stack<Integer> st = new Stack<>();
            int n = temperatures.length;
            int[] ans = new int[n];
            for (int i = 0, cur; i < n; i++) {
                while (!st.isEmpty() && temperatures[st.peek()] < temperatures[i]) {
                    cur = st.pop();
                    ans[cur] = i - cur;
                }
                st.push(i);
            }
            return ans;
        }
    }
}
